<?php 

    $this->PhpExcel->Excel();
    $this->PhpExcel->titulo_reporte("CONFIGURACIONES PDV", "LISTADO CONFIGURACIONES PDV");
    $this->PhpExcel->titulo_hoja("Configuraciones PDV");

    $ext = ($formato == 1) ? 'xlsx' : 'ods';
    $nombre = "LISTADO_CONFIGURACIONES_PDV".date("d_m_Y");

    $this->PhpExcel->hoja->getDefaultStyle()->applyFromArray(array('font' => array('name' => 'arial', 'size' => 10)));
    $this->PhpExcel->hoja->getStyle('A1')->applyFromArray(array('font' => array('bold' => true, 'size' => 12, 'color' => array('argb' => '8B0000'))));
    $this->PhpExcel->hoja->getStyle('A2')->applyFromArray(array('font' => array('bold' => true, 'size' => 11)));
    $this->PhpExcel->hoja->getStyle('A3')->applyFromArray(array('font' => array('bold' => false, 'size' => 10)));
    $this->PhpExcel->hoja->getStyle('A4')->applyFromArray(array('font' => array('bold' => false, 'size' => 10)));

    $arrStyleTitle = array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,
            'startcolor' => array('argb' => '81DAF5')),
        'font' => array('bold' => true,
            'color' => array('argb' => PHPExcel_Style_Color::COLOR_WHITE)),
        'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));

    $arrStyleTitleuno = array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,
            'startcolor' => array('argb' => 'EFFBFB')));

    $arrborderTitleuno = array('style' => PHPExcel_Style_Border::BORDER_DASHDOT, 'color' => array('argb' => '000000'));

    $this->PhpExcel->configura_celda('A', 40); //BANCO
    $this->PhpExcel->configura_celda('B', 40); //FORMA DE PAGO
    $this->PhpExcel->configura_celda('C', 30); //% RETENCION
    $this->PhpExcel->configura_celda('D', 30); //% RETENCION ISLR
    $this->PhpExcel->configura_celda('E', 20); //ESTATUS


    $index_title = 6;

    $j = 0;
    $tit[] = array('BANCO', 'STR', 'L');
    $tit[] = array('FORMA DE PAGO', 'STR', 'L');
    $tit[] = array('% DE RETENCION', 'STR', 'R');
    $tit[] = array('% DE RETENCION ISLR', 'STR', 'R');
    $tit[] = array('ESTADO', 'STR', 'C');
 

    foreach ($tit as $columnTitle) {
        $this->PhpExcel->valor_celda($j, $index_title, $columnTitle);
        $oColumn = $this->PhpExcel->obtener_columna($j, $index_title);
        $oRow = $this->PhpExcel->obtener_fila($j, $index_title);
        $this->PhpExcel->hoja->getStyle($oColumn . $oRow)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $this->PhpExcel->hoja->getStyle($oColumn . $oRow)->applyFromArray($arrStyleTitle);
        $this->PhpExcel->hoja->getStyle($oColumn . $oRow)->getBorders()->getAllBorders()->applyFromArray($arrborderTitleuno);
        $j++;
    }
    
    $this->PhpExcel->hoja->setAutoFilter("A$index_title:{$oColumn}{$oRow}");

    $fila = 7;

    foreach ($data as $detalle) {
    	if($detalle['RetencionTarjeta']['estatus']==1) $estatus="ACTIVO";
        $valores = array();
        $valores[] = array($detalle['Banco']['nombre'], 'STR', 'L');
        $valores[] = array($detalle['Formadepago']['nombre'], 'STR', 'L');
        $valores[] = array($detalle['RetencionTarjeta']['porreten'], 'STR', 'R');
        $valores[] = array($detalle['RetencionTarjeta']['porreten_islr'], 'STR', 'R');
        $valores[] = array($estatus, 'STR', 'C');
        $columna = 0;

        foreach ($valores as $valor) {
            $this->PhpExcel->valor_celda($columna, $fila, $valor);
            $oColumn = $this->PhpExcel->obtener_columna($columna, $fila);
            $oRow = $this->PhpExcel->obtener_fila($columna, $fila);
            if ($fila % 2 == 0) {
                $this->PhpExcel->hoja->getStyle($oColumn . $oRow)->applyFromArray($arrStyleTitleuno);
            }
            $this->PhpExcel->hoja->getStyle($oColumn . $oRow)->getBorders()->getAllBorders()->applyFromArray($arrborderTitleuno);
            $columna++;
        }
        $fila++;
    }

    $this->PhpExcel->mostrar($nombre, $ext); 

